package com.deloitte.sapnetweaver.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.deloitte.sapnetweaver.model.ModelLocator;
	
	import mx.controls.Alert;
	import mx.core.Container;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.utils.ObjectProxy;

	/**
	 * Abstract command object used as a super class to commands that retrieve chart data
	 */
	 
	public class BaseGetDataCommand implements ICommand, IResponder
	{
		protected const NO_DATA_FROM_SERVER_MESSAGE:String = "Session is expired, Please login again";
		protected var _model:ModelLocator = ModelLocator.getInstance();
		protected var _parentContainer:Container;
		protected var _event:CairngormEvent;
		
		public function execute(event:CairngormEvent):void
		{
			Alert("this method should not be used");
		}
		
		public function BaseGetDataCommand()
		{
			trace("BaseCommand..");
		}		
		
		// override this method
		
		public function result(data:Object):void
		{
			Alert.show("this method should not be used");
		}
		
		public function fault(info:Object):void
		{			
			Alert.show(FaultEvent(info).fault.rootCause.message);
		}
		
		/**
		 * Verify the data returned from an service call is not empty (null) 
		 * */
		 
		protected function isDataPresent(data:Object):Boolean
		{	
			var dataIsPresent:Boolean = true;
			
			if (data.result == null)
			{
				Alert.show(this.NO_DATA_FROM_SERVER_MESSAGE, "Error");
				
				dataIsPresent = false;
			}	
			
			return dataIsPresent;
		} 
	}
}